usbcpower2 2.2.0
Loading...
Searching...
No Matches
usbcpower2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef USBCPOWER2_H
29#define USBCPOWER2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define USBCPOWER2_REG_VENDOR_ID 0x01
74#define USBCPOWER2_REG_CONTROL 0x02
75#define USBCPOWER2_REG_INTERRUPT_STATUS 0x03
76#define USBCPOWER2_REG_CC_STATUS 0x04
77#define USBCPOWER2_REG_CON_DET_CONFIG 0x09
78#define USBCPOWER2_REG_VCONN_STATUS 0x0A
79#define USBCPOWER2_REG_RESET 0x10
80#define USBCPOWER2_REG_INTERRUPT_MASK 0x18
81#define USBCPOWER2_REG_INTERRUPT_REG_STATUS 0x19
82 // usbcpower2_reg
84
89
94
99#define USBCPOWER2_VENDOR_ID_DEVICE_VERSION 0x08
100#define USBCPOWER2_VENDOR_ID_DEVICE_VERSION_MASK 0xF8
101#define USBCPOWER2_VENDOR_ID_VENDOR_ID 0x03
102#define USBCPOWER2_VENDOR_ID_VENDOR_ID_MASK 0x07
103
108#define USBCPOWER2_CONTROL_RP_SEL_80UA 0x00
109#define USBCPOWER2_CONTROL_RP_SEL_180UA 0x08
110#define USBCPOWER2_CONTROL_RP_SEL_330UA 0x10
111#define USBCPOWER2_CONTROL_RP_SEL_MASK 0x18
112#define USBCPOWER2_CONTROL_MODE_SEL_DEVICE_UFP 0x00
113#define USBCPOWER2_CONTROL_MODE_SEL_HOST_DFP 0x02
114#define USBCPOWER2_CONTROL_MODE_SEL_DUAL_ROLE_DRP 0x04
115#define USBCPOWER2_CONTROL_MODE_SEL_MASK 0x06
116#define USBCPOWER2_CONTROL_INT_MASK_DIS 0x00
117#define USBCPOWER2_CONTROL_INT_MASK_EN 0x01
118#define USBCPOWER2_CONTROL_INT_MASK_MASK 0x01
119
124#define USBCPOWER2_INTERRUPT_STATUS_CABLE_DETACHED 0x02
125#define USBCPOWER2_INTERRUPT_STATUS_CABLE_ATTACHED 0x01
126
131#define USBCPOWER2_CC_STATUS_VBUS_DETECTED 0x80
132#define USBCPOWER2_CC_STATUS_RP_DET_STANDBY 0x00
133#define USBCPOWER2_CC_STATUS_RP_DET_STD_USB 0x20
134#define USBCPOWER2_CC_STATUS_RP_DET_1_5_A 0x40
135#define USBCPOWER2_CC_STATUS_RP_DET_3_0_A 0x60
136#define USBCPOWER2_CC_STATUS_RP_DET_MASK 0x60
137#define USBCPOWER2_CC_STATUS_PORT_STATUS_NOT_CONNECTED 0x00
138#define USBCPOWER2_CC_STATUS_PORT_STATUS_DFP_ATTACHED 0x04
139#define USBCPOWER2_CC_STATUS_PORT_STATUS_UFP_ATTACHED 0x08
140#define USBCPOWER2_CC_STATUS_PORT_STATUS_ANALOG_AUDIO 0x0C
141#define USBCPOWER2_CC_STATUS_PORT_STATUS_DEBUG 0x10
142#define USBCPOWER2_CC_STATUS_PORT_STATUS_MASK 0x1C
143#define USBCPOWER2_CC_STATUS_CC_POLARITY_CABLE_NOT_ATTACHED 0x00
144#define USBCPOWER2_CC_STATUS_CC_POLARITY_CC1_NORMAL 0x01
145#define USBCPOWER2_CC_STATUS_CC_POLARITY_CC2_REVERSED 0x02
146#define USBCPOWER2_CC_STATUS_CC_POLARITY_MASK 0x03
147
152#define USBCPOWER2_CON_DET_CONFIG_EN 0x00
153#define USBCPOWER2_CON_DET_CONFIG_DIS 0x01
154#define USBCPOWER2_CON_DET_CONFIG_MASK 0x01
155
160#define USBCPOWER2_VCONN_STATUS_STANDBY 0x00
161#define USBCPOWER2_VCONN_STATUS_CC1 0x01
162#define USBCPOWER2_VCONN_STATUS_CC2 0x02
163#define USBCPOWER2_VCONN_STATUS_MASK 0x03
164
169#define USBCPOWER2_RESET_SYSTEM 0x01
170
175#define USBCPOWER2_INTERRUPT_MASK_CC1_CC2_CHANGE_DIS 0x00
176#define USBCPOWER2_INTERRUPT_MASK_CC1_CC2_CHANGE_EN 0x10
177#define USBCPOWER2_INTERRUPT_MASK_CC1_CC2_CHANGE_MASK 0x10
178#define USBCPOWER2_INTERRUPT_MASK_ROLE_CHANGE_DIS 0x00
179#define USBCPOWER2_INTERRUPT_MASK_ROLE_CHANGE_EN 0x08
180#define USBCPOWER2_INTERRUPT_MASK_ROLE_CHANGE_MASK 0x08
181#define USBCPOWER2_INTERRUPT_MASK_ORIENTATION_DIS 0x00
182#define USBCPOWER2_INTERRUPT_MASK_ORIENTATION_EN 0x04
183#define USBCPOWER2_INTERRUPT_MASK_ORIENTATION_MASK 0x04
184#define USBCPOWER2_INTERRUPT_MASK_DEBUG_DIS 0x00
185#define USBCPOWER2_INTERRUPT_MASK_DEBUG_EN 0x02
186#define USBCPOWER2_INTERRUPT_MASK_DEBUG_MASK 0x02
187#define USBCPOWER2_INTERRUPT_MASK_AUDIO_DIS 0x00
188#define USBCPOWER2_INTERRUPT_MASK_AUDIO_EN 0x01
189#define USBCPOWER2_INTERRUPT_MASK_AUDIO_MASK 0x01
190
195#define USBCPOWER2_INTERRUPT_REG_STATUS_CC1_CC2_CHANGE 0x10
196#define USBCPOWER2_INTERRUPT_REG_STATUS_ROLE_CHANGE 0x08
197#define USBCPOWER2_INTERRUPT_REG_STATUS_ORIENTATION 0x04
198#define USBCPOWER2_INTERRUPT_REG_STATUS_DEBUG 0x02
199#define USBCPOWER2_INTERRUPT_REG_STATUS_AUDIO 0x01
200
206#define USBCPOWER2_DEVICE_ADDRESS 0x1D
207 // usbcpower2_set
209
214
219
224#define USBCPOWER2_MAP_MIKROBUS( cfg, mikrobus ) \
225 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
226 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
227 cfg.id_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
228 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
229 // usbcpower2_map // usbcpower2
232
237typedef struct
238{
239 // Input pins
240 digital_in_t id_pin;
241 digital_in_t int_pin;
242
243 // Modules
244 i2c_master_t i2c;
245
246 // I2C slave address
248
250
255typedef struct
256{
257 pin_name_t scl;
258 pin_name_t sda;
259
260 pin_name_t id_pin;
261 pin_name_t int_pin;
262
263 uint32_t i2c_speed;
264 uint8_t i2c_address;
265
267
278
284
295
310
324
338err_t usbcpower2_write_reg ( usbcpower2_t *ctx, uint8_t reg, uint8_t data_in );
339
353err_t usbcpower2_read_reg ( usbcpower2_t *ctx, uint8_t reg, uint8_t *data_out );
354
364
374
387
388#ifdef __cplusplus
389}
390#endif
391#endif // USBCPOWER2_H
392 // usbcpower2
394
395// ------------------------------------------------------------------------ END
err_t usbcpower2_check_com(usbcpower2_t *ctx)
USB-C Power 2 communication check function.
err_t usbcpower2_read_reg(usbcpower2_t *ctx, uint8_t reg, uint8_t *data_out)
USB-C Power 2 read register function.
uint8_t usbcpower2_get_id_pin(usbcpower2_t *ctx)
USB-C Power 2 get ID pin function.
err_t usbcpower2_write_reg(usbcpower2_t *ctx, uint8_t reg, uint8_t data_in)
USB-C Power 2 write register function.
err_t usbcpower2_init(usbcpower2_t *ctx, usbcpower2_cfg_t *cfg)
USB-C Power 2 initialization function.
uint8_t usbcpower2_get_int_pin(usbcpower2_t *ctx)
USB-C Power 2 get INT pin function.
err_t usbcpower2_default_cfg(usbcpower2_t *ctx)
USB-C Power 2 default configuration function.
void usbcpower2_cfg_setup(usbcpower2_cfg_t *cfg)
USB-C Power 2 configuration object setup function.
USB-C Power 2 Click configuration object.
Definition usbcpower2.h:256
uint32_t i2c_speed
Definition usbcpower2.h:263
pin_name_t id_pin
Definition usbcpower2.h:260
pin_name_t scl
Definition usbcpower2.h:257
pin_name_t int_pin
Definition usbcpower2.h:261
pin_name_t sda
Definition usbcpower2.h:258
uint8_t i2c_address
Definition usbcpower2.h:264
USB-C Power 2 Click context object.
Definition usbcpower2.h:238
digital_in_t int_pin
Definition usbcpower2.h:241
i2c_master_t i2c
Definition usbcpower2.h:244
digital_in_t id_pin
Definition usbcpower2.h:240
uint8_t slave_address
Definition usbcpower2.h:247
usbcpower2_return_value_t
USB-C Power 2 Click return value data.
Definition usbcpower2.h:273
@ USBCPOWER2_OK
Definition usbcpower2.h:274
@ USBCPOWER2_ERROR
Definition usbcpower2.h:275